home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Image.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.7 KB  |  91 lines

  1. //
  2. // "$Id: Fl_Image.cxx,v 1.5 1999/01/07 19:17:21 mike Exp $"
  3. //
  4. // Image drawing code for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. #include <FL/Fl.H>
  27. #include <FL/fl_draw.H>
  28. #include <FL/x.H>
  29. #include <FL/Fl_Widget.H>
  30. #include <FL/Fl_Menu_Item.H>
  31. #include <FL/Fl_Image.H>
  32.  
  33. void Fl_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
  34.   // account for current clip region (faster on Irix):
  35.   int X,Y,W,H; fl_clip_box(XP,YP,WP,HP,X,Y,W,H);
  36.   cx += X-XP; cy += Y-YP;
  37.   // clip the box down to the size of image, quit if empty:
  38.   if (cx < 0) {W += cx; X -= cx; cx = 0;}
  39.   if (cx+W > w) W = w-cx;
  40.   if (W <= 0) return;
  41.   if (cy < 0) {H += cy; Y -= cy; cy = 0;}
  42.   if (cy+H > h) H = h-cy;
  43.   if (H <= 0) return;
  44.   if (!id) {
  45.     id = (ulong)fl_create_offscreen(w, h);
  46.     fl_begin_offscreen((Fl_Offscreen)id);
  47.     fl_draw_image(array, 0, 0, w, h, d, ld);
  48.     fl_end_offscreen();
  49.   }
  50.   fl_copy_offscreen(X, Y, W, H, (Fl_Offscreen)id, cx, cy);
  51. }
  52.  
  53. Fl_Image::~Fl_Image() {
  54.   if (id) fl_delete_offscreen((Fl_Offscreen)id);
  55. }
  56.  
  57. static void image_labeltype(
  58.     const Fl_Label* o, int x, int y, int w, int h, Fl_Align a)
  59. {
  60.   Fl_Image* b = (Fl_Image*)(o->value);
  61.   int cx;
  62.   if (a & FL_ALIGN_LEFT) cx = 0;
  63.   else if (a & FL_ALIGN_RIGHT) cx = b->w-w;
  64.   else cx = (b->w-w)/2;
  65.   int cy;
  66.   if (a & FL_ALIGN_TOP) cy = 0;
  67.   else if (a & FL_ALIGN_BOTTOM) cy = b->h-h;
  68.   else cy = (b->h-h)/2;
  69.   b->draw(x,y,w,h,cx,cy);
  70. }
  71.  
  72. static void image_measure(const Fl_Label* o, int& w, int& h) {
  73.   Fl_Image* b = (Fl_Image*)(o->value);
  74.   w = b->w;
  75.   h = b->h;
  76. }
  77.  
  78. void Fl_Image::label(Fl_Widget* o) {
  79.   Fl::set_labeltype(_FL_IMAGE_LABEL, image_labeltype, image_measure);
  80.   o->label(_FL_IMAGE_LABEL, (const char*)this);
  81. }
  82.  
  83. void Fl_Image::label(Fl_Menu_Item* o) {
  84.   Fl::set_labeltype(_FL_IMAGE_LABEL, image_labeltype, image_measure);
  85.   o->label(_FL_IMAGE_LABEL, (const char*)this);
  86. }
  87.  
  88. //
  89. // End of "$Id: Fl_Image.cxx,v 1.5 1999/01/07 19:17:21 mike Exp $".
  90. //
  91.